﻿using MediatR;
using ProductionLine.API.Application.Command.Plan.Read;
using ProductionLine.Domain.Product;
using ProductionLine.ErrorCode;
using ProductionLine.Infrastructure.Interface;

namespace ProductionLine.API.Application.Handler.Plan.Read
{
    public class GetProductHandler : IRequestHandler<GetProductCommand, APIResult<List<ProductModel>>>
    {
        IBaseRepository<ProductModel> proRepo;

        public GetProductHandler(IBaseRepository<ProductModel> proRepo)
        {
            this.proRepo = proRepo;
        }

        public Task<APIResult<List<ProductModel>>> Handle(GetProductCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProductModel>> result = new APIResult<List<ProductModel>>();
            var res = proRepo.GetAll().ToList();
            result.Msg = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Success;
            return Task.FromResult(result);
        }
    }
}
